<template>
  <div>
    <van-nav-bar class="fix_header" title="管理收货地址" left-arrow @click-left="onClickLeft">
      <van-icon name="arrow-left" slot="left" color="#000" size="20" />
    </van-nav-bar>
    <div class="fix_next"></div>

    <div style="height: 10px;background: #f8f8f8;"></div>

    <div class="container">
      <div
        class="section"
        :class="{active:item.addressIsDefault==1}"
        v-for="(item,index) in list"
        :key="index"
        @click="select(item)"
      >
        <div class="activeLeft">
          <div class="item1">
            <span>收货人: {{item.addressRealName}}</span>
            <span style="margin-left: 20px;">{{formatMobile(item.addressMobile)}}</span>
          </div>
          <div class="item2">
            <div style="border-bottom: 1px solid #e5e5e5;padding-bottom: 20px;">
              <span>收货地址:</span>
              <span>{{item.addressAreaInfo}} {{item.address}}</span>
            </div>
          </div>
        </div>
        <div class="activeImg" v-if="item.addressIsDefault==1">
          <img
            src="../../../../../..../../static/img/lanhu/06.png"
            alt
            style="width: 20px;height: 15px;"
          />
        </div>
      </div>
    </div>

    <div class="footerBtn">
      <div style="padding: 20px 37.5px;">
        <van-button color="#FFD630" block @click="onAdd">新增收货地址</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getFun } from "@/api/publicFun.js";
let publicFun = getFun();
export default {
  data() {
    return {
      params: {
        userId: "",   
      },
      url2:this.$api+'/marketorderservice/api/v1/market/address/edit', // 修改位默认地址
      url1: this.$api + "/marketorderservice/api/v1/market/address/list",
      list: []
    };
  },
  methods: {
    onAdd() {
      this.link("/market/manager/addressAdd");
    },
    onEdit(item) {
      this.$refs.floor47.showPopup(item);
    },
    formatMobile(str) {
      let str1 = str.substring(0, 3);
      let str2 = str.substring(7, 11);
      return str1 + "****" + str2;
    },
    getData() {
      let that = this;
      this.$Axios2.postRequest(this.url1, this.params).then(function(res) {
        that.list = res.data;
      });
    },
    select(item) {
      if (item.addressIsDefault == 0) {
        let params = {
          memberId: item.memberId,
          addressIsDefault: 1,
          addressId: item.addressId
        };
        let that = this;
        this.$Axios2.Post(this.url2, params).then(function(res) {
          setTimeout(function() {
            that.getData();
          }, 300);
          that.$router.go(-1);
        });
      } else {
        this.$router.go(-1);
      }
    }
  },
  mixins: [publicFun], //混入
  mounted() {
    this.params.userId = this.$router.currentRoute.query.userId;
    this.getData();
  }
};
</script>

<style scoped="" lang="scss">
* {
  color: #333;
}
.section {
  font-size: 13px;
}
.section.active {
  background: #e5e5e5;
  display: flex;
  .activeLeft {
    width: 80%;
  }
}
.activeImg {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  img {
    border: 1px dashed #888888;
  }
}
.item1 {
  margin-bottom: 17.5px;
  padding-top: 20px;
  padding-left: 15px;
}
.item2 {
  padding-left: 15px;
}
.footerBtn {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
}
</style>